﻿@using Orchard.Utility.Extensions
@{
    Style.Require("NineSeas.Common");
    Style.Require("NineSeas.Authors.Author.Details");

    Script.Require("NineSeas.Authors.Author.Details");

    var title = ((string)Model.Author.DisplayName).Ellipsize(50);
    Layout.Title = title;

    var imageUrl = String.IsNullOrWhiteSpace(Model.Author.AvatarUrl) ?
            Href("~/Modules/NineSeas/Images/placeholder-photo.png")
            : Model.Author.AvatarUrl;
}
<div id="nineseas">
    <div id="author-profile" class="banner-orange" style="@(!String.IsNullOrEmpty(Model.Author.BannerColor) ? "background-color:" + Model.Author.BannerColor : "")">
        <div id="author-avatar"><img src="@imageUrl" alt="@Model.Author.DisplayName"/></div>
        <div id="author-profile-right">
            <div>
                <a href="javascript:;" class="like-button @(Model.IsLiked ? "liked" : "")">
                    @(Model.IsLiked ? T("Liked") : T("Like"))
                </a>
            </div>
            <a id="author-email" class="author-contact" href="mailto:@Model.User.Email"><div class="icon"></div><span>@Model.User.Email</span></a>
        </div>
        <div id="author-profile-center">
            <div id="author-status-message">@Model.Author.StatusMessage</div>
            <div id="author-display-name">@Model.Author.DisplayName</div>
            <div id="author-dateofbirth">@Model.Author.DateOfBirth</div>
            <div id="author-book-count">@T("{0} books", Model.Author.BookCount.ToString("#,#;(#,#);0"))</div>
            <div id="author-like-count">@T("{0} likes", Model.Author.TotalLikes.ToString("#,#;(#,#);0"))</div>
        </div>
        <div style="clear: both;"></div>
    </div>
    @{var i = 0;}
    @foreach (var book in Model.Books)
    {
        var bookImageUrl = String.IsNullOrWhiteSpace(book.ImageUrl) ?
            Href("~/Modules/NineSeas/Images/placeholder-book.png")
            : book.ImageUrl;
        var url = Url.Action("Index", "BookView", new { name = book.NameOnUrl }, Request.Url.Scheme);
    <div class="book-item @(i % 2 == 0 ? "book-item-even" : "")">
        <a href="@Url.Action("Index", "BookView", new { name = book.NameOnUrl })" class="book-link-view">
            <img src="@bookImageUrl" alt="@book.Name"/>
        </a>
        <a href="@Url.Action("Index", "BookView", new { name = book.NameOnUrl })" class="book-link-view">
            <div class="book-item-content">
                <div class="book-name">@book.Name</div>
                <div class="book-introduction">
                    @(new MvcHtmlString(book.Introduction))
                </div>
            </div>
        </a>
        <div class="book-item-footer">
            <div class="book-item-footer-left">
                <span class="book-item-likes">@(book.TotalLikes.ToString("#,#;(#,#);0"))</span>
                <span class="book-item-views">@(book.TotalViews.ToString("#,#;(#,#);0"))</span>
            </div>
            <div class="book-item-footer-right">
                <span class="book-share-button">
                    Share
                    <div class="services">
                        <a href="https://www.facebook.com/sharer/sharer.php?u=@url" class="share-button facebook-share">Facebook</a>
                        <a href="http://www.twitter.com/share?url=@url" class="share-button twitter-share">Tweet</a>
                        <a href="http://www.linkedin.com/shareArticle?mini=true&url=@url" class="share-button linkedin-share">Linked In</a>
                        <a href="https://plus.google.com/share?url=@url" class="share-button gplus-share">Google +</a>
                        <a href="http://pinterest.com/pin/create/button/?url=@url" class="share-button pinterest-share">Pinterest</a>
                    </div>
                </span>
                <span class="book-created-date">@book.CreatedDate.ToString("dd/MM/yyyy")</span>
            </div>
            <div style="clear: both;"></div>
        </div>
    </div>
        i++;
    }


    @Display(New.InfiniteScroll(Container: "#nineseas", Item: ".book-item", Pagination: "#paging", Next: "#nextPage"))
    
    <div style="clear: both;"></div>
    <div id="paging">
        @if (Model.Paging.CurrentPage > 0)
        {
        <a href="@Url.Action("Details", "Authors", new { id = Model.Author.Id, pageIndex = Model.Paging.CurrentPage - 1, pageSize = Model.Paging.PageSize })" id="previousPage">&lt; @T("Previous")</a>
        }
        
        @if (Model.Paging.CurrentPage < Model.Paging.TotalPages - 1)
        {
        <a href="@Url.Action("Details", "Authors", new { id = Model.Author.Id, pageIndex = Model.Paging.CurrentPage + 1, pageSize = Model.Paging.PageSize })" id="nextPage">@T("Next") &gt;</a>
        }
    </div>
    <div id="footer-push"></div>
</div>
@Display(New.Controls_SharePanel(
    Url: @Url.Action("Index", "Author", new {name = Model.Author.User.UserName}, Request.Url.Scheme),
    ImageUrl: imageUrl,
    Description: @Model.Author.StatusMessage,
    Type: "profile"
))
<script type="text/javascript">
    $(document).ready(function () {
        $(".like-button").click(function () {
            var isLiked = $(".like-button").hasClass("liked");

            $.get("@Url.Action("Like", "Authors", new {id = Model.Author.Id, like = Model.IsLiked ? "0" : "1"})",
                function (data) {
                    if (data && data.success) {
                        if (data.caption) {
                            $(".like-button").html(data.caption);
                        }

                        if (isLiked) {
                            $(".like-button").removeClass("liked");
                        } else {
                            $(".like-button").addClass("liked");
                        }
                    }
                },
                "json");
        });
    });
</script>